/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.<br>
 */
package com.ce.pms.charge.web;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import com.ce.pms.base.web.PmsBaseAction;
import com.ce.pms.charge.model.PeriodDomain;
import com.ce.pms.charge.service.IExcelExportService;
import com.ce.pms.charge.service.IExcelImportService;
import com.ce.pms.charge.service.IMeterDataRegisterService;
import com.ce.pms.charge.vo.OriginalMeterDataVO;
import com.ce.pms.common.util.PmsUtilityComparator;
import com.ce.pms.customer.service.IProRightService;
import com.ce.pms.customer.vo.ProRightVO;
import com.ce.pms.exception.UILayerException;
import com.ce.pms.house.model.HouseDomain;
import com.ce.pms.house.model.MeterType;
import com.ce.pms.house.service.IBuildingService;
import com.ce.pms.house.service.IHouseService;
import com.ce.pms.house.service.IManageAreaService;
import com.ce.pms.house.service.IMeterService;
import com.ce.pms.house.service.IProRightChangeService;
import com.ce.pms.house.vo.BuildingVO;
import com.ce.pms.house.vo.HouseVO;
import com.ce.util.DateUtil;
import com.ce.util.XMLAbout;
import com.sitechasia.webx.core.annotation.Out;
import com.sitechasia.webx.core.annotation.Read;
import com.sitechasia.webx.core.annotation.Scope;
import com.sitechasia.webx.core.support.Page;

/**
 * 功能描述：走表数据录入<br>
 * @author 易贤建 创建日期：2008-8-14<br>
 */
public class MeterDataRegisterAction extends PmsBaseAction {
	private final  String cache_search_str = "CACHE_SEARCH_STR";//缓存查询条件的KEY
	private final String cache_errorList = "EXCEPTION_ERROR"; //导入时,错误数据缓存KEY
	private final String cache_warnList = "EXCEPTION_WARN";  //导入时,有疑问数据缓存KEY
	private final String cache_excelFile = "EXCEL_FILE";     //保存读入的excel文件

	private IManageAreaService manageAreaService = null;
	private IBuildingService buildingService = null;  //楼栋
	private IHouseService houseService = null;  //房屋
	private IMeterService meterService = null; //走表
	private IProRightService  proRightService = null; //产权
	private IMeterDataRegisterService meterDataRegisterService = null;//走表数据录入
	private IExcelImportService excelImportService = null;
	private IExcelExportService excelExportService = null;
	private IProRightChangeService proRightChangeService = null;
	/**
	 * 功能描述: 初始化走表数据录入主页面 <br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-14  <br>
	 */
	public String initMain(){
		initCacheData();

		return "main";
	}
	/**
	 * 功能描述: 初始化列表页面 <br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initList(){
		setAttribute("totalRows", Integer.valueOf(0));
		return "list";
	}
	/**
	 * 功能描述:  初始化俺用户录入走表数据页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-15  <br>
	 */
	public String initByUser(@Read(key="houseId")Long houseId){
		initDateCache();
		initHouseCache(houseId);
		return "byUser";
	}
	/**
	 * 功能描述: 初始化按水表录入页面 <br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-20  <br>
	 */
	public String initByWater(@Read(key="houseId")Long houseId){
		initDateCache();
		initHouseCache(houseId);
		return "byWater";
	}
	/**
	 * 功能描述:  按电表录入数据<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-20  <br>
	 */
	public String initByAmmeter(@Read(key="houseId")Long houseId){
		initDateCache();
		initHouseCache(houseId);
		return "byAmmeter";
	}
	/**
	 * 功能描述:  初始化导入文件页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-26  <br>
	 */
	public String initImport(){
		return "import";
	}
	/**
	 * 功能描述:  初始化导出页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-26  <br>
	 */
	public String initExport(){
		//缓存所有收费管理区
		List precinctList = manageAreaService.getAllChargePrecinct();
		setAttribute("precincts", precinctList);
		return "export";
	}
	/**
	 * 功能描述: 缓存查询对象 <br>
	 * @param queryDataVO
	 * Create author:yixianjian <br>
	 * Create on:2008-8-14  <br>
	 */
	public void setSearchVO(@Read OriginalMeterDataVO queryDataVO){
		setAttribute(this.cache_search_str, queryDataVO,Scope.SESSION);
	}
	/**
	 * 功能描述:  获取缓存的查询对象.如果该对象不存在,则新建一个<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-20  <br>
	 */
	public OriginalMeterDataVO getSearchVO(){
		OriginalMeterDataVO cacheObj = (OriginalMeterDataVO)getAttribute(this.cache_search_str);
		return cacheObj == null ? new OriginalMeterDataVO() : cacheObj;
	}

	/**
	 * 功能描述:  列表查询方法<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-14  <br>
	 */
	public String list(@Read(key = "ec_p", defaultValue="1")Integer currentPage,
					   @Read(key = "ec_crd", defaultValue="12") Integer pageSize){
		OriginalMeterDataVO queryDataVO = getSearchVO();
		Page page = meterDataRegisterService.getChargeDatasVOsByPage(queryDataVO, currentPage, pageSize);
		setAttribute("meterData", page.getResult());
		setAttribute("totalRows", Integer.valueOf(String.valueOf(page.getTotalCount())));
		return "list";
	}
	/**
	 * 功能描述:  如果发生异常则跳转到异常主页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-9-1  <br>
	 */
	public String listExceptionMain(){
		return "exceptionMain";
	}
	/**
	 * 功能描述:  在导入时发生错误,需要列出发生错误的列表,这个方法就是初始化错误列表<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-9-1  <br>
	 */
	public String listException(@Read(key="type") @Out(key="type") String type){
		String cacheKey = "error".equals(type) ? this.cache_errorList : ("warn".equals(type) ? this.cache_warnList : null);
		if(cacheKey == null)
			throw new UILayerException("charge:charge_meterData_error_type_exception",UILayerException.ERROR);
		List list = (List)getAttribute(cacheKey, Scope.SESSION);
		Integer totalRows = list != null ? list.size() : Integer.valueOf(0);
		setAttribute("totalRows", Integer.valueOf(totalRows));
		return "exceptionList";
	}
	/**
	 * 功能描述: 按户录入走表数据 <br>
	 * @param meterData
	 * Create author:yixianjian <br>
	 * Create on:2008-8-19  <br>
	 */
	public void addByUser(@Read OriginalMeterDataVO meterData){
		Set<OriginalMeterDataVO> meterDataSet = processOriginalMeterDataVOByAdd(meterData);
		meterDataRegisterService.registerMeterDataByDoor(meterDataSet);
	}
	/**
	 * 功能描述: 按水表添加走表数据<br>
	 * @param meterData  抄表数据相关信息
	 * Create author:yixianjian <br>
	 * Create on:2008-8-20  <br>

	 */
	public void addByWater(@Read OriginalMeterDataVO meterData){
		meterData.setMeterType("001");
		meterData.setCreator(super.getUserId());
		meterDataRegisterService.addOriginalMeterData(meterData);
	}

	/**
	 * 功能描述:  按电表录入数据<br>
	 * @param meterData
	 * Create author:yixianjian <br>
	 * Create on:2008-8-20  <br>
	 */
	public void addByAmmeter(@Read OriginalMeterDataVO meterData){
		meterData.setMeterType("002");
		meterData.setCreator(super.getUserId());
		meterDataRegisterService.addOriginalMeterData(meterData);
	}
	/**
	 * 功能描述:  修改走表数据<br>
	 * @param originalMeterDataVO
	 * Create author:yixianjian <br>
	 * Create on:2008-8-26  <br>
	 */
	public void editMeterData(@Read OriginalMeterDataVO originalMeterDataVO){
		originalMeterDataVO.setCreator(super.getUserId());
		meterDataRegisterService.editOriginalMeterDataDoCheck(originalMeterDataVO);
	}
	/**
	 * 功能描述:  调整走表读数<br>
	 * @param originalMeterDataVO
	 * Create author:yixianjian <br>
	 * Create on:2008-9-27  <br>
	 */
	public void regulateMeterData(@Read OriginalMeterDataVO originalMeterDataVO){
		originalMeterDataVO.setModifier(super.getUserId());
		meterDataRegisterService.adjustMeterData(originalMeterDataVO);
	}
	/**
	 * 功能描述:  给定ID 作废对应的走表数据<br>
	 * @param meterDataId
	 * Create author:yixianjian <br>
	 * Create on:2008-8-26  <br>
	 */
	public void abateMeterData(@Read(key="meterDataId")Long meterDataId){
		meterDataRegisterService.abateMeterDataById(meterDataId, super.getUserId());
	}
	/**
	 * 功能描述:  导入文件<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-27  <br>
	 * @throws Exception
	 */
	public String importFile() throws Exception{
        //获取上传的excel
		HSSFWorkbook workbook = (HSSFWorkbook)getAttribute(this.cache_excelFile, Scope.SESSION);
		excelImportService.readExcelAndSave(workbook,super.getUserId());
		//清空缓存
		removeAttribute(this.cache_errorList, Scope.SESSION);
		removeAttribute(this.cache_warnList, Scope.SESSION);
		removeAttribute(this.cache_excelFile, Scope.SESSION);
		//设置成功标识
		setAttribute("success", Boolean.valueOf(true));
		return "exceptionInfo";
	}
	/**
	 * 功能描述:  导入前  需要检查下是否有错误数据、有疑问数据<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-9-9  <br>
	 */
	@SuppressWarnings("unchecked")
	public String checkImportExcelFile() throws Exception{
		//获取上传的文件
		FileItem fileItem = getFileItemForExcel();
		//检查文件是否异常
		if(!validateFileType(fileItem.getName())){
			setAttribute("filetypeException", getLocaleMessage("charge:charege_meterdata_filetype_exception"));
			return "exceptionInfo";
		}
        //获取上传的excel
		HSSFWorkbook workbook = new HSSFWorkbook(fileItem.getInputStream());
		Map<String,List> map = excelImportService.checkTheExcel(workbook);
		if(map != null || map.size() > 0){
			if(map.get("error")!= null && map.get("error").size() > 0)
				setAttribute(this.cache_errorList, map.get("error"),Scope.SESSION);
			else
				removeAttribute(this.cache_errorList, Scope.SESSION);

			if(map.get("warn")!= null && map.get("warn").size() > 0)
				setAttribute(this.cache_warnList, map.get("warn"), Scope.SESSION);
			else
				removeAttribute(this.cache_warnList, Scope.SESSION);
		}
		String returnPage = "exceptionInfo";
		//如果没有错误的数据,缓存读入的文件  在导入完成后 要求remove
		if(getAttribute(this.cache_errorList, Scope.SESSION) == null){
			setAttribute(this.cache_excelFile, workbook,Scope.SESSION);
			returnPage = "exceptionInfo";
		}
		if(getAttribute(this.cache_errorList, Scope.SESSION) == null &&
			getAttribute(this.cache_warnList, Scope.SESSION) == null)
			returnPage = "importFile";
		return returnPage;
	}
	/**
	 * 功能描述: 导出文件 <br>
	 * Create author:yixianjian <br>
	 * Create on:2008-8-28  <br>
	 * @throws Exception
	 */
	public void exportFile(@Read(key="precinctId")Long precinctId,
							@Read(key="buildingId")Long buildingId) throws Exception{
		HSSFWorkbook hssfWorkdbook = excelExportService.createHSSFWorkbook(buildingId);
		String fileName = getFileName();
		getResponse().setHeader("Content-Disposition", "attachment;" + fileName);
		getResponse().setContentType("application/vnd.ms-excel");
		hssfWorkdbook.write(getResponse().getOutputStream());
		getResponse().getOutputStream().flush();
		getResponse().getOutputStream().close();
	}

	/**
	 * 功能描述:  验证输入的房号是否存在.<br>
	 * 有三种情况: null:标识输入的为NULL;
	 * 			 noexist:标识输入房号对应的房屋不存在;
	 *           houseId+houseNumber:对方房号的房屋存在,放回房屋ID和房号
	 * @param houseNumber
	 * Create author:yixianjian <br>
	 * Create on:2008-8-18  <br>
	 */
	public void validateHouseNumber(@Read(key="houseNumber")String houseNumber,
									@Read(key="meterType")String meterType){
		String flag = null;
		Long houseId = null;
		if(houseNumber == null || "".equals(houseNumber))
			flag = "";
		if(flag == null){ //验证房号是否存在
			HouseDomain houseDomain = houseService.getHouseByNumber(houseNumber.trim());
			flag = houseDomain == null? super.getLocaleMessage("charge:charge_meterDataRegister_houseNumber_noexist") :getHouseInfoForJson(houseDomain);
			houseId = houseDomain == null? null : houseDomain.getKeyword();
		}
		if(houseId != null){
			flag = validateAllInfo(houseId,meterType);
		}
		renderText(flag == null ? "true" : flag);
	}
	/**
	 * 功能描述:验证这条走表数据是否可以被修改<br>
	 * @param chargeDataId
	 * Create author:yixianjian <br>
	 * Create on:2008-10-17  <br>
	 */
	public void validateEditable(@Read(key="chargeDataId")Long chargeDataId){
		meterDataRegisterService.checkEditMeterDataState(chargeDataId,false);
	}
	/**
	 * 功能描述:验证是否可以调整走表读数<br>
	 * @param chargeDataId
	 * Create author:yixianjian <br>
	 * Create on:2008-10-17  <br>
	 */
	public void validateAdjustable(@Read(key="chargeDataId")Long chargeDataId){
		meterDataRegisterService.checkAjustMeterDataState(chargeDataId);
	}
	/**
	 * 功能描述:检查是否可以作废数据<br>
	 * @param chargeDataId
	 * Create author:yixianjian <br>
	 * Create on:2008-10-17  <br>
	 */
	public void validateAbateable(@Read(key="chargeDataId")Long chargeDataId){
		meterDataRegisterService.checkabateMeterDataState(chargeDataId);
	}

	/**
	 * 功能描述:  根据房号查询上次抄表数据<br>
	 * @param houseNumber
	 * Create author:yixianjian <br>
	 * Create on:2008-8-18  <br>
	 */
	public void getMeterDataByHouseNum(@Read(key="houseNumber")String houseNumber){

			Map<String,OriginalMeterDataVO> meterData = meterDataRegisterService.findMeterDataVOBy(houseNumber);
			StringBuffer meterInfo =  new StringBuffer();
			//处理业主名称
			String owner = houseService.getOwnerNameBy(houseNumber);
			meterInfo.append("{'owner':'").append(owner).append("'");
			//处理水表和电表上次读数
			meterInfo.append(",").append(getMeterInfoForJson(meterData.get("001")));
			meterInfo.append(",").append(getMeterInfoForJson(meterData.get("002")));
			//处理房屋ID
			HouseDomain houseDomain = houseService.getHouseByNumber(houseNumber);
			meterInfo.append(",'houseId':'").append(houseDomain.getKeyword()).append("'");
			meterInfo.append("}");

		renderText(meterInfo.toString());
	}
	/**
	 * 功能描述:  为不同走表类型查询上次读数<br>
	 * meterType 001  标识水表
	 * 			 002  标识电表
	 * @param houseId
	 * @param houseNumber
	 * @param meterType
	 * Create author:yixianjian <br>
	 * Create on:2008-8-20  <br>
	 */
	public void getMeterDataForMeterType(@Read(key="houseNumber")String houseNumber,
			  							 @Read(key="meterType")String meterType){
		OriginalMeterDataVO originalMeterData = meterDataRegisterService.findMeterDataVOByHouseNumber(houseNumber, meterType);

		StringBuffer meterInfo =  new StringBuffer("{");
		//处理业主名称
		String owner = houseService.getOwnerNameBy(houseNumber);
		meterInfo.append("'owner':'").append(owner).append("'");
		//处理房屋ID
		meterInfo.append(",'houseId':'").append(originalMeterData.getHouseId()).append("'");
		//处理上次读数
		meterInfo.append(",").append(getMeterInfoForJson(originalMeterData));
		meterInfo.append("}");

		renderText(meterInfo.toString());
	}
	/**
	 * 功能描述:  联动下来框,加载楼栋方法<br>
	 * @param selectId
	 * @param targetId
	 * Create author:yixianjian <br>
	 * Create on:2008-8-28  <br>
	 * @throws Exception
	 */
    public void unitedSelect(@Read(key = "selectId")Long selectId,
							 @Read(key = "targetId")String targetId) throws Exception{
    	List buildList = manageAreaService.getBuildingsBy(selectId);
    	String xmlStr = XMLAbout.convertListToSelectXML(buildList,"name","keyword");
    	super.renderXML(xmlStr);
    }
    /***
     * 功能描述: 走表数据详细信息 <br>
     * @param meterDataId
     * @return
     * Create author:yandawei <br>
     * Create on:2008-9-18  <br>
     * Edit author:  <br>
     * Edit on:    <br>
     * Why:     <br>
     */
    public String getMeterDataDetail(@Read(key="meterDataId") Long meterDataId){
    	OriginalMeterDataVO meterData = meterDataRegisterService.findMeterDataVOByID(meterDataId);
    	setAttribute("meterData", meterData);
    	return "meterDataDetail";
    }
    /**
     * 功能描述:  创建导出EXCEL文件的雯靖名。根据 meter+当前时间组成<br>
     * @return
     * Create author:yixianjian <br>
     * Create on:2008-8-28  <br>
     */
	private String getFileName() {
		StringBuffer fileName = new StringBuffer("filename=Meter");
		fileName.append(DateUtil.formatDate(DateUtil.getCurrentDate(), "yyyyMMddhhmmss", Locale.CHINA));
		fileName.append(".xls");
		return fileName.toString();
	}
	/**
	 * 功能描述: 从request中获取excel输入流 <br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-27  <br>
	 */
	@SuppressWarnings("unchecked")
	private FileItem getFileItemForExcel(){
        DiskFileItemFactory factory=new DiskFileItemFactory();
        factory.setSizeThreshold(4096);
        ServletFileUpload fileUpload=new ServletFileUpload(factory);
        FileItem fileItem = null;
        try{
            //开始读取上传信息
            List<FileItem> filedList  = fileUpload.parseRequest(getRequest());
            for(int i = 0; filedList != null && i < filedList.size() ; i++){
            	//如果不是上传的文件  就进入到下一个循环
            	if(filedList.get(i).isFormField()) continue;
            	fileItem = filedList.get(i); break;
            }
        }catch(Exception e){
        	throw new UILayerException(getLocaleMessage("charge:charege_meterdata_read_file_exception"));
        }
        //如果fileItem 为空 则说明没输入文件  提示用户输入文件
        if(fileItem == null) throw new UILayerException("charge:charege_meterdata_input_file_exception");
		return fileItem;
	}
	/**
	 * 功能描述:  验证文件格式必须为xsl，office其他版本(如office 2007 为xslx)不支持,其他文件类型不支持<br>
	 * @param file
	 * Create author:yixianjian <br>
	 * Create on:2008-8-27  <br>
	 */
	private boolean validateFileType(String fileName){
		String fileNameTemp = fileName.toLowerCase();
		if(fileNameTemp.endsWith("xls")) return true;
		return false;
	}

	/**
	 * 功能描述: 在抄表数据录入前,得验证是否能录入抄表数据. <br>
	 * 没登产权不能登记、没登记水表或电表不能登记
	 * @param houseId
	 * @return noexistproright  对应房屋没产权,
	 *         noexistwater  对应房屋没登记水表
	 *         noexistammeter 对应房屋没登记电表
	 * Create author:yixianjian <br>
	 * Create on:2008-8-21  <br>
	 */
	private String validateAllInfo(Long houseId,String meterType){
		String result = null;
		if(result == null){ //验证房号是否有产权
			ProRightVO prorightvo =  proRightService.getEffectiveProRightByHouseId(houseId);
			result = (prorightvo == null ? super.getLocaleMessage("charge:charge_meterDataRegister_houseNumber_noexistproright") :null);
		}
		if(result == null ){//验证房号对应的房屋是否登记水表
			if(meterType == null || "001".equals(meterType)){
				boolean flag = meterService.checkMeterBy(houseId, "001");
				result = flag ? null : super.getLocaleMessage("charge:charge_meterDataRegister_houseNumber_noexistwater");
			}
		}
		if(result == null){//验证房号对应房屋是否登记电表
			if(meterType == null || "002".equals(meterType)){
				boolean flag = meterService.checkMeterBy(houseId, "002");
				result = flag ? null : super.getLocaleMessage("charge:charge_meterDataRegister_houseNumber_noexistammeter");
			}
		}
		if(result == null){//验证房号对应房屋是否处于退伙中
			if(houseId != null ){
				String flag = proRightChangeService.checkTheHouseNumber(houseId);
				result = (flag == null ? null : super.getLocaleMessage("charge:charge_meterDataRegister_houseNumber_ingoout"));
			}
		}
		return result;
	}
	/**
	 * 功能描述:缓存日期到request以便页面初始化用<br>
	 * Create author:yixianjian <br>
	 * Create on:2008-10-17  <br>
	 */
	private void initDateCache(){
		Date date = meterDataRegisterService.getDate();
		setAttribute("sysDate", DateUtil.convertDateToStr(date, "yyyy-MM-dd"));
	}
	/**
	 * 功能描述:  添加时处理水表、电表录入处理.要求生成一个水表类型的VO,一个电表VO<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private Set<OriginalMeterDataVO> processOriginalMeterDataVOByAdd(OriginalMeterDataVO meterData){
		Set<OriginalMeterDataVO> meterDataVOSet = new HashSet<OriginalMeterDataVO>();
		OriginalMeterDataVO shuiMeterData = new OriginalMeterDataVO();
		shuiMeterData.setHouseId(meterData.getHouseId());
		shuiMeterData.setOwners(meterData.getOwners());
		shuiMeterData.setThisReading(new BigDecimal(getRequest().getParameter("shui_thisReading")));
		shuiMeterData.setRecordTime(meterData.getRecordTime());
		shuiMeterData.setCreator(super.getUserId());
		shuiMeterData.setMeterType("001");
		String lastReading = getRequest().getParameter("shui_lastReading");
		if(lastReading != null && !"".equals(lastReading))
			shuiMeterData.setLastReading(new BigDecimal( lastReading));
		meterDataVOSet.add(shuiMeterData);

		OriginalMeterDataVO dianMeterData = new OriginalMeterDataVO();
		dianMeterData.setHouseId(meterData.getHouseId());
		dianMeterData.setOwners(meterData.getOwners());
		dianMeterData.setThisReading(new BigDecimal(getRequest().getParameter("dian_thisReading")));
		dianMeterData.setRecordTime(meterData.getRecordTime());
		dianMeterData.setMeterType("002");
		dianMeterData.setCreator(super.getUserId());
		lastReading = getRequest().getParameter("dian_lastReading");
		if(lastReading != null && !"".equals(lastReading))
			dianMeterData.setLastReading(new BigDecimal( lastReading ));
		meterDataVOSet.add(dianMeterData);
		return meterDataVOSet;
	}
	/**
	 * 功能描述:  <br>
	 * @param meterDataVO
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private String getMeterInfoForJson(OriginalMeterDataVO meterDataVO){
		StringBuffer meterInfo = new StringBuffer();
		meterInfo.append("'type").append(meterDataVO.getMeterType()).append("':");
		meterInfo.append("{").append("'lastReading':'").append(meterDataVO.getThisReading()).append("'");
		meterInfo.append(",'maxSize':'").append(meterDataVO.getMAXZ()).append("'");
		meterInfo.append("}");
		return meterInfo.toString();
	}
	/**
	 * 功能描述:  拼装房屋ID、和房号<br>
	 * @param houseDomain
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-18  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private String getHouseInfoForJson(HouseDomain houseDomain){
		if(houseDomain == null) return "null";

		StringBuffer houseInfo = new StringBuffer("{");
		houseInfo.append("'houseId':'").append( houseDomain.getKeyword() ).append("',");
		houseInfo.append("'houseNumber':'").append(houseDomain.getHouseNumber()).append("'}");
		return houseInfo.toString();
	}
	/**
	 * 功能描述:  初始化主页面时,有楼栋、走表类型、状态、收费周期下拉框数据缓存<br>
	 * Create author:yixianjian <br>
	 * Create on:2008-8-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private void initCacheData(){
		//楼栋列表
		List<BuildingVO> buildList = buildingService.getBuildingListByAreaId(getAreaId());
		Collections.sort(buildList, PmsUtilityComparator.getComparator());
		//走表类型列表
		List<MeterType> meterTypeList = meterService.getMeterTypeList();
		//收费周期列表
		List<PeriodDomain> periodDomainList = meterDataRegisterService.getAllPeriodDo();

		setAttribute("buildList", buildList);
		setAttribute("meterTypeList", meterTypeList);
		setAttribute("periodList", periodDomainList);
	}
	/**
	 * 功能描述:保存并新增时, <br>
	 * @param houseId
	 * Create author:yixianjian <br>
	 * Create on:2008-10-17  <br>
	 */
	private void initHouseCache(Long houseId){
		if(houseId == null) return;

		HouseVO houseVO = houseService.queryNextHouseById(houseId);
		setAttribute("houseVO", houseVO);
	}
	/**
	 * 功能描述: 获取楼盘的ID，以后这个方法需要放到基类,获取 管理区ID从基类获取 <br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private Long getAreaId(){
		return Long.valueOf("1");
	}
	public void setBuildingService(IBuildingService buildingService) {
		this.buildingService = buildingService;
	}
	public void setMeterDataRegisterService(
			IMeterDataRegisterService meterDataRegisterService) {
		this.meterDataRegisterService = meterDataRegisterService;
	}
	public void setMeterService(IMeterService meterService) {
		this.meterService = meterService;
	}
	public void setHouseService(IHouseService houseService) {
		this.houseService = houseService;
	}
	public void setProRightService(IProRightService proRightService) {
		this.proRightService = proRightService;
	}
	public void setExcelExportService(IExcelExportService excelExportService) {
		this.excelExportService = excelExportService;
	}
	public void setExcelImportService(IExcelImportService excelImportService) {
		this.excelImportService = excelImportService;
	}
	public void setManageAreaService(IManageAreaService manageAreaService) {
		this.manageAreaService = manageAreaService;
	}
	/**
	 * @param proRightChangeService the proRightChangeService to set
	 */
	public void setProRightChangeService(
			IProRightChangeService proRightChangeService) {
		this.proRightChangeService = proRightChangeService;
	}
}
